﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TfsUtils.Utils.Concrete
{
    public class ConsoleEnvironment : IEnvironment
    {
        public MessageLevel MinimumLevel { get; set; }

        public ConsoleEnvironment(MessageLevel minimumLevel)
        {
            MinimumLevel = minimumLevel;
        }

        public void SendMessage(string message, MessageLevel level)
       {
           if (level >= MinimumLevel)
           {
               var oldColor = Console.ForegroundColor;
               switch (level)
               {
                   case MessageLevel.Debug:
                       Console.ForegroundColor = ConsoleColor.White;
                       break;
                   case MessageLevel.Info:
                       Console.ForegroundColor = ConsoleColor.Gray;
                       break;
                   case MessageLevel.Message:
                       Console.ForegroundColor = ConsoleColor.Green;
                       break;
                   case MessageLevel.Warn:
                       Console.ForegroundColor = ConsoleColor.Yellow;
                       break;
                   case MessageLevel.Error:
                       Console.ForegroundColor = ConsoleColor.Red;
                       break;
                   default:
                       throw new ArgumentOutOfRangeException("level");
               }

               Console.WriteLine(message);
               Console.ForegroundColor = oldColor;
           }
       }
    }
}
